﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HZ.Supervise.Model;
using HZ.Supervise.IBLL;

public partial class MasterPage_New : System.Web.UI.MasterPage
{
    public string NavBar_pageID { get; set; }
    protected void Page_Load(object sender, EventArgs e)
    {

        //ViewState["MasterID"] = Request.QueryString["sessionid"];
        ViewState["master"] = URLUtil.GetSuperviseQueryFromURL(Request);

        //给页面的菜单标记赋值
        SuperviseQuery query = (SuperviseQuery)ViewState["master"];
        if (!string.IsNullOrEmpty(query._Titile))
        {
            this.Page.Title = query._Titile;
        }

        if (!IsPostBack)
        {
            if (string.IsNullOrEmpty(this.Request["sessionid"]))
            {
                Session["PagesHistoryJJJ"] = null;
            }

            if (UserSiteMapPath1.VisitHistory.Count < 6)
            {
                Stack<PageInfo> list = UserSiteMapPath1.VisitHistory;
                PageInfo pi = new PageInfo() { Title = this.Page.Title, URL = Request.Url.ToString() };
                bool flag = false;
                foreach (var item in list)
                {
                    if (item.Title == pi.Title)
                    {
                        flag = true;
                    }
                }
                if (flag)
                {
                    while (list.Peek().Title != pi.Title)
                    {
                        UserSiteMapPath1.ModifyLastLink();
                    }
                }
                else
                {
                    UserSiteMapPath1.AddLink(pi);
                }

            }
            UserSiteMapPath1.SetText();
        }
    }
    protected void lbtnHos_Click(object sender, EventArgs e)
    {
        //string commandname = ((LinkButton)sender).CommandName.ToString();

        //string url = System.Configuration.ConfigurationManager.AppSettings[commandname];

        //SuperviseQuery query = (SuperviseQuery)ViewState["master"];
        //if (query == null)
        //{
        //    query = new SuperviseQuery();
        //}
        //string sessionid = Guid.NewGuid().ToString();
        //Session[sessionid] = query;
        //Response.Redirect(string.Format("{0}?sessionid={1}", url, sessionid));
    }

    protected void DropOther_SelectedIndexChanged(object sender, EventArgs e)
    {
        //if (DropOther.SelectedValue != "")
        //{
        //    string url = System.Configuration.ConfigurationManager.AppSettings[DropOther.SelectedValue];

        //    SuperviseQuery query = (SuperviseQuery)ViewState["master"];
        //    if (query == null)
        //    {
        //        query = new SuperviseQuery();
        //    }
        //    string sessionid = Guid.NewGuid().ToString();
        //    Session[sessionid] = query;
        //    Response.Redirect(string.Format("{0}?sessionid={1}", url, sessionid));
        //}
    }
    public void btnClear_Click(object sender, EventArgs e)
    {
        //if (ViewState["MasterID"] != null)
        //    Session.Remove(ViewState["MasterID"].ToString());
        ViewState.Clear();
        //Session["PagesHistoryZZZ"] = null;
        HZ.Supervise.Model.User user = CurrentAccount.GetUser();

        ShowColumns sc = ShowColumns.ShowColumn;

        Session.Clear();
        // Session["ACCOUNT_KEY"] = user;
        CurrentAccount.SetUser(user);
        ShowColumns.ShowColumn = sc;

        Response.Redirect(this.Request.Url.ToString());
    }
}
